Telegram Group & Telegram Channel
Кэшированные атрибуты

Во встроенном пакете functools есть классный декоратор @cached_property, который позволяет кэшировать результат метода и загнать его в атрибут.

Таким образом, при первом обращении к атрибуту производятся вычисления в методе, а при дальнейших берется уже кэшированное значение.

Подобное кэшеирование полезно в случаях, когда в методе производятся вычисления, которые нагружают систему и занимают много времени.

По сути, @cached_property можно сравнить с комбинацией декораторов @property (про это был пост) и @functools.lru_cache (и про это тоже).

#functools #cached_property



tg-me.com/python_academy/498
Create:
Last Update:

Кэшированные атрибуты

Во встроенном пакете functools есть классный декоратор @cached_property, который позволяет кэшировать результат метода и загнать его в атрибут.

Таким образом, при первом обращении к атрибуту производятся вычисления в методе, а при дальнейших берется уже кэшированное значение.

Подобное кэшеирование полезно в случаях, когда в методе производятся вычисления, которые нагружают систему и занимают много времени.

По сути, @cached_property можно сравнить с комбинацией декораторов @property (про это был пост) и @functools.lru_cache (и про это тоже).

#functools #cached_property

BY Python Academy




Share with your friend now:
tg-me.com/python_academy/498

View MORE
Open in Telegram


Python Academy Telegram | DID YOU KNOW?

Date: |

How Does Telegram Make Money?

Telegram is a free app and runs on donations. According to a blog on the telegram: We believe in fast and secure messaging that is also 100% free. Pavel Durov, who shares our vision, supplied Telegram with a generous donation, so we have quite enough money for the time being. If Telegram runs out, we will introduce non-essential paid options to support the infrastructure and finance developer salaries. But making profits will never be an end-goal for Telegram.

Telegram today rolling out an update which brings with it several new features.The update also adds interactive emoji. When you send one of the select animated emoji in chat, you can now tap on it to initiate a full screen animation. The update also adds interactive emoji. When you send one of the select animated emoji in chat, you can now tap on it to initiate a full screen animation. This is then visible to you or anyone else who's also present in chat at the moment. The animations are also accompanied by vibrations. This is then visible to you or anyone else who's also present in chat at the moment. The animations are also accompanied by vibrations.

Python Academy from us


Telegram Python Academy
FROM USA